/*
    SEL - Simple DirectMedia Layer Extension Library
    Copyright (C) 2001, 2002 Matej Knopp <knopp@users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __sel_base_h__
#define __sel_base_h__

#include "sdl.h"
#include "rect.h"
#include "surface.h"
#include "cdrom.h"
#include "debug.h"
#include "error.h"
#include "events.h"
#include "joystick.h"
#include "keyboard.h"
#include "mouse.h"
#include "mutex.h"
#include "object.h"
#include "rwops.h"
#include "thread.h"
#include "videoinfo.h"
#include "uta.h"

namespace SEL
{

/*! \name Subsystems 
  These flags can be OR'd and used as parameter in the init function.
 */ 
//@{
const Uint32 INIT_TIMER       = SDL::INIT_TIMER; 
const Uint32 INIT_AUDIO       = SDL::INIT_AUDIO;
const Uint32 INIT_VIDEO       = SDL::INIT_VIDEO;
const Uint32 INIT_CDROM       = SDL::INIT_CDROM;
const Uint32 INIT_JOYSTICK    = SDL::INIT_JOYSTICK;	
const Uint32 INIT_NOPARACHUTE = SDL::INIT_NOPARACHUTE;
const Uint32 INIT_EVENTTHREAD = SDL::INIT_EVENTTHREAD;
const Uint32 INIT_EVERYTHING  = SDL::INIT_EVERYTHING;
//@}

//! Load SDL dynamically linked library and initialize the subsytems
//! specified by \a flags (And those satisfying dependencies).
/*!
  Unless the INIT_NOPARACHUTE flag is set, it will install cleanup signal
  handlers for some commonly ignored fatal signals (like SIGSEGV).
  On any error it will throw an exception with SEL::Error parameter 
  containing the error message.
  \param flags - The subsystems you want to init (OR'd).
  */
inline void init (Uint32 flags)
{
	if (SDL::Init (flags) < 0)
	{
		debug ("Couldn't init SDL");
		throw Error (SDL::GetError ());
	}
	else if (SDL::WasInit (INIT_VIDEO))
	{
		VideoInfo::getVideoInfo ();
	}
}	

//! Initialize specific SDL subsystem(s).
/*!
  On any error it throws an exception with SEL::Error class as the
  parameter containing the error message.  
  \param flags - the subsystem(s) you want to initialize (OR'd).
 */  
inline void initSubSystem (Uint32 flags)
{
	if (SDL::InitSubSystem (flags) < 0)
	{
		debug ("Couldn't init subsystem(s)");
		throw Error (SDL::GetError ());
	}
}

//! Clean up specific SDL subsystem(s)
/*!
  \param flags - the subsystem(s) you want to clean up (OR'd).
 */
inline void quitSubSystem (Uint32 flags)
{
	SDL::QuitSubSystem (flags);
}

//! Return mask of specified subsystems which have been initialized.
/*!
  If \a flag parameter is omitted it returns the mask of all initialized 
  subsystems.
  \param flags - the subsytems you want to query (OR'd).
 */
inline Uint32 wasInit (Uint32 flags = 0)
{
	return SDL::WasInit (flags);
}

//! Clean up all initialized subsystems and unload the dynamically linked
//! library.
/*!
  You should call it upon all exit conditions.
 */
inline void quit (void)
{
	SDL::Quit ();
}

} // namespace SEL

#endif // __sel_base_h__
